package com.ruoyi.Api;


import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.countrybus.domain.SysStation;
import com.ruoyi.project.countrybus.domain.SysStationRoute;
import com.ruoyi.project.countrybus.service.ISysStationRouteService;
import com.ruoyi.project.countrybus.service.ISysStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("路线API")
@RestController
@RequestMapping("/api/route")
public class RouteApi extends BaseController
{
    @Autowired
    private ISysStationRouteService sysStationRouteService;


    @Autowired
    private ISysStationService sysStationService;


    /**
     * 查询路线站点信息列表
     */
    @ApiOperation("查询路线站点信息列表")
    @GetMapping("/list")
    public TableDataInfo list(SysStationRoute sysStationRoute)
    {
        startPage();
        List<SysStationRoute> list = sysStationRouteService.selectSysStationRouteList(sysStationRoute);
        return getDataTable(list);
    }


    /**
     * 获取路线站点信息详细信息
     */
    @ApiOperation("通过ID获取路线站点信息详细信息")
    @GetMapping(value = "/{routeId}")
    public AjaxResult getInfo(@PathVariable("routeId") Long routeId)
    {
        return AjaxResult.success(sysStationRouteService.selectSysStationRouteByRouteId(routeId));
    }

    /**
     * 新增路线站点信息
     */
    @ApiOperation("新增路线站点信息")
    @PostMapping
    public AjaxResult add(@RequestBody SysStationRoute sysStationRoute)
    {
        return toAjax(sysStationRouteService.insertSysStationRoute(sysStationRoute));
    }

    /**
     * 修改路线站点信息
     */
    @ApiOperation("修改路线站点信息")
    @PutMapping
    public AjaxResult edit(@RequestBody SysStationRoute sysStationRoute)
    {
        return toAjax(sysStationRouteService.updateSysStationRoute(sysStationRoute));
    }

    /**
     * 删除路线站点信息
     */
    @ApiOperation("删除路线站点信息")
    @DeleteMapping("/{routeIds}")
    public AjaxResult remove(@PathVariable Long[] routeIds)
    {
        return toAjax(sysStationRouteService.deleteSysStationRouteByRouteIds(routeIds));
    }


    /**
     * 查询路线完整站点列表
     */
    @ApiOperation("查询路线完整站点列表")
    @GetMapping("/station/list/{routeId}")
    public TableDataInfo stationlist(@PathVariable("routeId") Long routeId) {
        startPage();
        List<SysStation> list = sysStationService.selectSysStationListByRouteId(routeId);
        return getDataTable(list);
    }

}
